<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>OpenFOAM-2.3.x 中的 twoPhaseEulerFoam 解析之 TurbulenceModel | Giskard&#39;s CFD Learning Tricks</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="在 kineticTheoryModel 类的解读时前面提到过， kineticTheoryModel 使用了跟湍流模型一样的接口。这一篇，就来看一下 twoPhaseEulerFoam 中的湍流模型。">
<meta property="og:type" content="article">
<meta property="og:title" content="OpenFOAM-2.3.x 中的 twoPhaseEulerFoam 解析之 TurbulenceModel">
<meta property="og:url" content="http://xiaopingqiu.github.io/2015/09/19/TFM-TurbulenceModel/index.html">
<meta property="og:site_name" content="Giskard's CFD Learning Tricks">
<meta property="og:description" content="在 kineticTheoryModel 类的解读时前面提到过， kineticTheoryModel 使用了跟湍流模型一样的接口。这一篇，就来看一下 twoPhaseEulerFoam 中的湍流模型。">
<meta property="og:image" content="/image/TFM/turbulenceModel.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="OpenFOAM-2.3.x 中的 twoPhaseEulerFoam 解析之 TurbulenceModel">
<meta name="twitter:description" content="在 kineticTheoryModel 类的解读时前面提到过， kineticTheoryModel 使用了跟湍流模型一样的接口。这一篇，就来看一下 twoPhaseEulerFoam 中的湍流模型。">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

##ga('create', '[object Object]', 'auto');
ga('create', 'UA-62501686-1', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->


</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Giskard&#39;s CFD Learning Tricks</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">CFD and Scientific Computing</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
          <a class="main-nav-link" href="/atom.xml">Rss</a>
        
          <a class="main-nav-link" href="/about">About</a>
        
      </nav>
      <nav id="sub-nav">
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="q" value="site:http://xiaopingqiu.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-TFM-TurbulenceModel" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/09/19/TFM-TurbulenceModel/" class="article-date">
  <time datetime="2015-09-19T04:38:20.000Z" itemprop="datePublished">2015-09-19</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/OpenFOAM/">OpenFOAM</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      OpenFOAM-2.3.x 中的 twoPhaseEulerFoam 解析之 TurbulenceModel
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>在 <code>kineticTheoryModel</code> 类的解读时前面提到过， <code>kineticTheoryModel</code> 使用了跟湍流模型一样的接口。这一篇，就来看一下 <code>twoPhaseEulerFoam</code> 中的湍流模型。  </p>
<a id="more"></a>
<p>OpenFOAM-2.3.x 中的<code>twoPhaseEulerFoam</code> 流体相可以调用 RAS 和 LES 湍流模型，固相可以使用两种计算固相应力的“湍流模型”。<br>湍流模型的调用是通过 phaseModel 来进行的，具体的过程放到最后来讲，这里先说一下最重要的 <code>divDevRhoReff</code> 函数的形式，主要有三种类型：用于固相的 <code>phasePressure</code> 和  <code>kineticTheoryModel</code> 以及用于流体相的 RAS 模型或 LES 模型，以 <code>kEpsilon</code> 模型为例。此外，在”pEqn.H”里，还需要用到 <code>pPrime()</code> 函数，这个函数主要是在处理颗粒相的压力时有意义，所以，在 <code>phasePressure</code> 和 <code>kineticTheoryModel</code> 两个模型中，这个函数也需要关注一下。</p>
<h5 id="1_phasePressure">1  phasePressure</h5><p> 很显然，这个是用于固相的，只考虑所谓固相压力，所以理论上， <code>divDevRhoReff</code>函数应该是对固相动量方程没有贡献的，实际上也正是如此，其定义如下：<br><figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="constant">Foam:</span><span class="symbol">:tmp&lt;Foam</span><span class="symbol">:</span><span class="symbol">:fvVectorMatrix&gt;</span></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:RASModels</span><span class="symbol">:</span><span class="symbol">:phasePressureModel</span><span class="symbol">:</span><span class="symbol">:divDevRhoReff</span></span><br><span class="line">(</span><br><span class="line">    volVectorField&amp; <span class="constant">U</span></span><br><span class="line">) const</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span> tmp&lt;fvVectorMatrix&gt;</span><br><span class="line">    (</span><br><span class="line">        new fvVectorMatrix</span><br><span class="line">        (</span><br><span class="line">            <span class="constant">U,</span></span><br><span class="line">            this-&gt;rho<span class="constant">_</span>.dimensions()*dimensionSet(<span class="number">0</span>, <span class="number">4</span>, -<span class="number">2</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">        )</span><br><span class="line">    );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>经测验，这一项对 fvVectorMatrix 的贡献是零。</p>
 <figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="constant">Foam:</span><span class="symbol">:tmp&lt;Foam</span><span class="symbol">:</span><span class="symbol">:volScalarField&gt;</span></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:RASModels</span><span class="symbol">:</span><span class="symbol">:phasePressureModel</span><span class="symbol">:</span><span class="symbol">:pPrime</span>() const</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span></span><br><span class="line">        g0<span class="constant">_</span></span><br><span class="line">       *min</span><br><span class="line">        (</span><br><span class="line">            exp(preAlphaExp<span class="constant">_</span>*(this-&gt;alpha<span class="constant">_</span> - alphaMax<span class="constant">_</span>)),</span><br><span class="line">            expMax<span class="constant">_</span></span><br><span class="line">        );</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:tmp&lt;Foam</span><span class="symbol">:</span><span class="symbol">:surfaceScalarField&gt;</span></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:RASModels</span><span class="symbol">:</span><span class="symbol">:phasePressureModel</span><span class="symbol">:</span><span class="symbol">:pPrimef</span>() const</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span></span><br><span class="line">        g0<span class="constant">_</span></span><br><span class="line">       *min</span><br><span class="line">        (</span><br><span class="line">            exp(preAlphaExp<span class="constant">_</span>*(<span class="symbol">fvc:</span><span class="symbol">:interpolate</span>(this-&gt;alpha<span class="constant">_</span>) - alphaMax<span class="constant">_</span>)),</span><br><span class="line">            expMax<span class="constant">_</span></span><br><span class="line">        );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><code>phasePressure</code> 模型计算的“固相压力”为<br>$$<br>pPrime = g0\cdot \mathrm{min}(e^{preAlphaExp\cdot (\varepsilon_s - \varepsilon_{s,max})},expMax)<br>$$<br>注意这里的$g0$ 与 <code>radialModel</code> 中的$g_0$ 不是一个概念！</p>
<h5 id="2_kineticTheory">2  kineticTheory</h5><p>KTGF 模型， 代码如下：<br><figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line">  <span class="constant">Foam:</span><span class="symbol">:tmp&lt;Foam</span><span class="symbol">:</span><span class="symbol">:fvVectorMatrix&gt;</span></span><br><span class="line">  <span class="constant">Foam:</span><span class="symbol">:RASModels</span><span class="symbol">:</span><span class="symbol">:kineticTheoryModel</span><span class="symbol">:</span><span class="symbol">:divDevRhoReff</span></span><br><span class="line">  (</span><br><span class="line">     volVectorField&amp; <span class="constant">U</span></span><br><span class="line">  ) const</span><br><span class="line">  &#123;</span><br><span class="line">     <span class="keyword">return</span></span><br><span class="line">     (</span><br><span class="line">       - <span class="symbol">fvm:</span><span class="symbol">:laplacian</span>(this-&gt;rho<span class="constant">_</span>*this-&gt;nut<span class="constant">_</span>, <span class="constant">U)</span></span><br><span class="line">       - <span class="symbol">fvc:</span><span class="symbol">:div</span></span><br><span class="line">         (</span><br><span class="line">             (this-&gt;rho<span class="constant">_</span>*this-&gt;nut<span class="constant">_</span>)*dev2(<span class="constant">T(</span><span class="symbol">fvc:</span><span class="symbol">:grad</span>(<span class="constant">U)</span>))</span><br><span class="line">           + ((this-&gt;rho<span class="constant">_</span>*lambda<span class="constant">_</span>)*<span class="symbol">fvc:</span><span class="symbol">:div</span>(this-&gt;phi<span class="constant">_</span>))</span><br><span class="line">            *dimensioned&lt;symmTensor&gt;(<span class="string">"I"</span>, dimless, <span class="symbol">symmTensor:</span><span class="symbol">:I</span>)</span><br><span class="line">         )</span><br><span class="line">     );</span><br><span class="line">  &#125;</span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">  </span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:tmp&lt;Foam</span><span class="symbol">:</span><span class="symbol">:volScalarField&gt;</span></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:RASModels</span><span class="symbol">:</span><span class="symbol">:kineticTheoryModel</span><span class="symbol">:</span><span class="symbol">:pPrime</span>() const</span><br><span class="line">&#123;</span><br><span class="line">    <span class="regexp">//</span> <span class="constant">Local </span>references</span><br><span class="line">    const volScalarField&amp; alpha = this-&gt;alpha<span class="constant">_</span>;</span><br><span class="line">    const volScalarField&amp; rho = phase<span class="constant">_</span>.rho();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span></span><br><span class="line">    (</span><br><span class="line">        <span class="constant">Theta_</span></span><br><span class="line">       *granularPressureModel<span class="constant">_</span>-&gt;granularPressureCoeffPrime</span><br><span class="line">        (</span><br><span class="line">            alpha,</span><br><span class="line">            radialModel<span class="constant">_</span>-&gt;g<span class="number">0</span>(alpha, alphaMinFriction<span class="constant">_</span>, alphaMax<span class="constant">_</span>),</span><br><span class="line">            radialModel<span class="constant">_</span>-&gt;g0prime(alpha, alphaMinFriction<span class="constant">_</span>, alphaMax<span class="constant">_</span>),</span><br><span class="line">            rho,</span><br><span class="line">            e<span class="constant">_</span></span><br><span class="line">        )</span><br><span class="line">     +  frictionalStressModel<span class="constant">_</span>-&gt;frictionalPressurePrime</span><br><span class="line">        (</span><br><span class="line">            alpha,</span><br><span class="line">            alphaMinFriction<span class="constant">_</span>,</span><br><span class="line">            alphaMax<span class="constant">_</span></span><br><span class="line">        )</span><br><span class="line">    );</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:tmp&lt;Foam</span><span class="symbol">:</span><span class="symbol">:surfaceScalarField&gt;</span></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:RASModels</span><span class="symbol">:</span><span class="symbol">:kineticTheoryModel</span><span class="symbol">:</span><span class="symbol">:pPrimef</span>() const</span><br><span class="line">&#123;</span><br><span class="line">    <span class="regexp">//</span> <span class="constant">Local </span>references</span><br><span class="line">    const volScalarField&amp; alpha = this-&gt;alpha<span class="constant">_</span>;</span><br><span class="line">    const volScalarField&amp; rho = phase<span class="constant">_</span>.rho();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="symbol">fvc:</span><span class="symbol">:interpolate</span></span><br><span class="line">    (</span><br><span class="line">        <span class="constant">Theta_</span></span><br><span class="line">       *granularPressureModel<span class="constant">_</span>-&gt;granularPressureCoeffPrime</span><br><span class="line">        (</span><br><span class="line">            alpha,</span><br><span class="line">            radialModel<span class="constant">_</span>-&gt;g<span class="number">0</span>(alpha, alphaMinFriction<span class="constant">_</span>, alphaMax<span class="constant">_</span>),</span><br><span class="line">            radialModel<span class="constant">_</span>-&gt;g0prime(alpha, alphaMinFriction<span class="constant">_</span>, alphaMax<span class="constant">_</span>),</span><br><span class="line">            rho,</span><br><span class="line">            e<span class="constant">_</span></span><br><span class="line">        )</span><br><span class="line">     +  frictionalStressModel<span class="constant">_</span>-&gt;frictionalPressurePrime</span><br><span class="line">        (</span><br><span class="line">            alpha,</span><br><span class="line">            alphaMinFriction<span class="constant">_</span>,</span><br><span class="line">            alphaMax<span class="constant">_</span></span><br><span class="line">        )</span><br><span class="line">    );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这一部分详细的公式已在 <code>kineticTheoryModel</code> 解读部分分析了，不再赘述。</p>
<h5 id="3_kEpsilon_(OpenFOAM-2-3-x/src/TurbulenceModels/turbulenceModels/RAS/kEpsilon)">3  kEpsilon (<code>OpenFOAM-2.3.x/src/TurbulenceModels/turbulenceModels/RAS/kEpsilon</code>)</h5><p>这个代表的是RAS湍流模型。（其实还有 LES 模型，只是 RAS 与 LES 的 <code>divDevRhoReff</code>函数形式应该是一样的），函数所在代码路径为：<code>OpenFOAM-2.3.x/src/TurbulenceModels/turbulenceModels/eddyViscosity/eddyViscosity.C</code></p>
<figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">template&lt;class <span class="constant">BasicTurbulenceModel&gt;</span></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:tmp&lt;Foam</span><span class="symbol">:</span><span class="symbol">:fvVectorMatrix&gt;</span></span><br><span class="line"><span class="constant">Foam:</span><span class="symbol">:eddyViscosity&lt;BasicTurbulenceModel&gt;</span><span class="symbol">:</span><span class="symbol">:divDevRhoReff</span></span><br><span class="line">(</span><br><span class="line">    volVectorField&amp; <span class="constant">U</span></span><br><span class="line">) const</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span></span><br><span class="line">    (</span><br><span class="line">      - <span class="symbol">fvm:</span><span class="symbol">:laplacian</span>(this-&gt;alpha<span class="constant">_</span>*this-&gt;rho<span class="constant">_</span>*this-&gt;nuEff(), <span class="constant">U)</span></span><br><span class="line">      - <span class="symbol">fvc:</span><span class="symbol">:div</span>((this-&gt;alpha<span class="constant">_</span>*this-&gt;rho<span class="constant">_</span>*this-&gt;nuEff())*dev2(<span class="constant">T(</span><span class="symbol">fvc:</span><span class="symbol">:grad</span>(<span class="constant">U)</span>)))</span><br><span class="line">    );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><code>kEpsilon</code> 类中没有重新定义 <code>pPrime()</code> 函数，而是直接继承 <code>PhaseCompressibleTurbulenceModel</code> 类中的定义，返回零，这里就不列出代码了。</p>
<h4 id="湍流模型的调用">湍流模型的调用</h4><p>湍流模型的调用过程，值得看一下，重点是看一下湍流模型类的继承派生关系，以 <code>kineticTheoryModel</code> 为例。<br><code>kineticTheoryModel</code> 类的声明和构造函数部分如下：<br><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> kineticTheoryModel</span><br><span class="line">:</span><br><span class="line">    public eddyViscosity</span><br><span class="line">    &lt;</span><br><span class="line">        RASModel&lt;PhaseCompressibleTurbulenceModel&lt;phaseModel&gt; &gt;</span><br><span class="line">    &gt;</span><br><span class="line">&#123;</span><br><span class="line">    ......</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Foam::RASModels::kineticTheoryModel::kineticTheoryModel</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> volScalarField&amp; <span class="keyword">alpha</span>,</span><br><span class="line">    <span class="keyword">const</span> volScalarField&amp; rho,</span><br><span class="line">    <span class="keyword">const</span> volVectorField&amp; <span class="keyword">U</span>,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; phi,</span><br><span class="line">    <span class="keyword">const</span> transportModel&amp; phase,</span><br><span class="line">    <span class="keyword">const</span> word&amp; propertiesName,</span><br><span class="line">    <span class="keyword">const</span> word&amp; <span class="keyword">type</span></span><br><span class="line">)</span><br><span class="line">:</span><br><span class="line">    eddyViscosity&lt;RASModel&lt;PhaseCompressibleTurbulenceModel&lt;phaseModel&gt; &gt; &gt;</span><br><span class="line">    (</span><br><span class="line">        <span class="keyword">type</span>,</span><br><span class="line">        <span class="keyword">alpha</span>,</span><br><span class="line">        rho,</span><br><span class="line">        <span class="keyword">U</span>,</span><br><span class="line">        alphaRhoPhi,</span><br><span class="line">        phi,</span><br><span class="line">        phase,</span><br><span class="line">        propertiesName</span><br><span class="line">    ),</span><br><span class="line">    ......</span><br></pre></td></tr></table></figure></p>
<p>可见， <code>kineticTheoryModel</code> 类继承自 <code>eddyViscosity</code> 类，并且用 <code>RASModel&lt;PhaseCompressibleTurbulenceModel&lt;phaseModel&gt; &gt;</code> 来实例化<code>eddyViscosity</code> 类中的模板参数。</p>
<p>再来看<code>eddyViscosity</code> 类：<br><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">template</span>&lt;<span class="keyword">class</span> BasicTurbulenceModel&gt;</span><br><span class="line"><span class="keyword">class</span> eddyViscosity</span><br><span class="line">:</span><br><span class="line">    <span class="keyword">public</span> BasicTurbulenceModel</span><br><span class="line">&#123;</span><br><span class="line"><span class="keyword">protected</span>:</span><br><span class="line">    <span class="comment">// Protected data</span></span><br><span class="line">    </span><br><span class="line">        <span class="comment">// Fields</span></span><br><span class="line">        volScalarField nut_;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Protected Member Functions</span></span><br><span class="line">        <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">correctNut</span><span class="params">()</span> </span>= <span class="number">0</span>;</span><br><span class="line">        </span><br><span class="line"><span class="keyword">template</span>&lt;<span class="keyword">class</span> BasicTurbulenceModel&gt;</span><br><span class="line">Foam::eddyViscosity&lt;BasicTurbulenceModel&gt;::eddyViscosity</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> word&amp; modelName,</span><br><span class="line">    <span class="keyword">const</span> alphaField&amp; alpha,</span><br><span class="line">    <span class="keyword">const</span> rhoField&amp; rho,</span><br><span class="line">    <span class="keyword">const</span> volVectorField&amp; U,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; phi,</span><br><span class="line">    <span class="keyword">const</span> transportModel&amp; transport,</span><br><span class="line">    <span class="keyword">const</span> word&amp; propertiesName</span><br><span class="line">)</span><br><span class="line">:</span><br><span class="line">    BasicTurbulenceModel</span><br><span class="line">    (</span><br><span class="line">        modelName,</span><br><span class="line">        alpha,</span><br><span class="line">        rho,</span><br><span class="line">        U,</span><br><span class="line">        alphaRhoPhi,</span><br><span class="line">        phi,</span><br><span class="line">        transport,</span><br><span class="line">        propertiesName</span><br><span class="line">    ),</span><br><span class="line"></span><br><span class="line">    nut_</span><br><span class="line">    (</span><br><span class="line">        IOobject</span><br><span class="line">        (</span><br><span class="line">            IOobject::groupName(<span class="string">"nut"</span>, U.group()),</span><br><span class="line">            <span class="keyword">this</span>-&gt;runTime_.timeName(),</span><br><span class="line">            <span class="keyword">this</span>-&gt;mesh_,</span><br><span class="line">            IOobject::MUST_READ,</span><br><span class="line">            IOobject::AUTO_WRITE</span><br><span class="line">        ),</span><br><span class="line">        <span class="keyword">this</span>-&gt;mesh_</span><br><span class="line">    )</span><br><span class="line">&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<p>注意，这里有意思的来了， <code>eddyViscosity</code> 类继承自其模板参数代表的类，具体继承自哪个类，要等模板实例化了才知道。这种用法我还是头一次接触。根据上面 <code>kineticTheoryModel</code> 类的构造函数，可知 <code>eddyViscosity</code> 类在当前分析的情况下，将继承自 <code>RASModel&lt;PhaseCompressibleTurbulenceModel&lt;phaseModel&gt; &gt;</code> 。</p>
<p>继续看 <code>RASModel</code> 类的定义：<br><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br></pre></td><td class="code"><pre><span class="line">template&lt;<span class="keyword">class</span> BasicTurbulenceModel&gt;</span><br><span class="line"><span class="keyword">class</span> RASModel</span><br><span class="line">:</span><br><span class="line">    public BasicTurbulenceModel</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">protected:</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Protected data</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//- RAS coefficients dictionary</span></span><br><span class="line">        dictionary RASDict_;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//- Turbulence on/off flag</span></span><br><span class="line">        Switch turbulence_;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//- Flag to print the model coeffs at run-time</span></span><br><span class="line">        Switch printCoeffs_;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//- Model coefficients dictionary</span></span><br><span class="line">        dictionary coeffDict_;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//- Lower limit of k</span></span><br><span class="line">        dimensionedScalar kMin_;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//- Lower limit of epsilon</span></span><br><span class="line">        dimensionedScalar epsilonMin_;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//- Lower limit for omega</span></span><br><span class="line">        dimensionedScalar omegaMin_;</span><br><span class="line">      </span><br><span class="line">       ......</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">// constructor</span></span><br><span class="line">template&lt;<span class="keyword">class</span> BasicTurbulenceModel&gt;</span><br><span class="line">Foam::RASModel&lt;BasicTurbulenceModel&gt;::RASModel</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> word&amp; <span class="keyword">type</span>,</span><br><span class="line">    <span class="keyword">const</span> alphaField&amp; <span class="keyword">alpha</span>,</span><br><span class="line">    <span class="keyword">const</span> rhoField&amp; rho,</span><br><span class="line">    <span class="keyword">const</span> volVectorField&amp; <span class="keyword">U</span>,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; phi,</span><br><span class="line">    <span class="keyword">const</span> transportModel&amp; transport,</span><br><span class="line">    <span class="keyword">const</span> word&amp; propertiesName</span><br><span class="line">)</span><br><span class="line">:</span><br><span class="line">    BasicTurbulenceModel</span><br><span class="line">    (</span><br><span class="line">        <span class="keyword">alpha</span>,</span><br><span class="line">        rho,</span><br><span class="line">        <span class="keyword">U</span>,</span><br><span class="line">        alphaRhoPhi,</span><br><span class="line">        phi,</span><br><span class="line">        transport,</span><br><span class="line">        propertiesName</span><br><span class="line">    ),</span><br><span class="line"></span><br><span class="line">    RASDict_(this-&gt;subOrEmptyDict(<span class="string">"RAS"</span>)),</span><br><span class="line">    turbulence_(RASDict_.<span class="keyword">lookup</span>(<span class="string">"turbulence"</span>)),</span><br><span class="line">    printCoeffs_(RASDict_.lookupOrDefault&lt;Switch&gt;(<span class="string">"printCoeffs"</span>, false)),</span><br><span class="line">    coeffDict_(RASDict_.subOrEmptyDict(<span class="keyword">type</span> + <span class="string">"Coeffs"</span>)),</span><br><span class="line"></span><br><span class="line">    kMin_</span><br><span class="line">    (</span><br><span class="line">        dimensioned&lt;<span class="keyword">scalar</span>&gt;::lookupOrAddToDict</span><br><span class="line">        (</span><br><span class="line">            <span class="string">"kMin"</span>,</span><br><span class="line">            RASDict_,</span><br><span class="line">            SMALL,</span><br><span class="line">            sqr(dimVelocity)</span><br><span class="line">        )</span><br><span class="line">    ),</span><br><span class="line"></span><br><span class="line">    epsilonMin_</span><br><span class="line">    (</span><br><span class="line">        dimensioned&lt;<span class="keyword">scalar</span>&gt;::lookupOrAddToDict</span><br><span class="line">        (</span><br><span class="line">            <span class="string">"epsilonMin"</span>,</span><br><span class="line">            RASDict_,</span><br><span class="line">            SMALL,</span><br><span class="line">            kMin_.dimensions()/dimTime</span><br><span class="line">        )</span><br><span class="line">    ),</span><br><span class="line"></span><br><span class="line">    omegaMin_</span><br><span class="line">    (</span><br><span class="line">        dimensioned&lt;<span class="keyword">scalar</span>&gt;::lookupOrAddToDict</span><br><span class="line">        (</span><br><span class="line">            <span class="string">"omegaMin"</span>,</span><br><span class="line">            RASDict_,</span><br><span class="line">            SMALL,</span><br><span class="line">            dimless/dimTime</span><br><span class="line">        )</span><br><span class="line">    )</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// Force the construction of the mesh deltaCoeffs which may be needed</span></span><br><span class="line">    <span class="comment">// for the construction of the derived models and BCs</span></span><br><span class="line">    this-&gt;mesh_.deltaCoeffs();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><code>RASModel</code> 类也是继承自模板参数代表的类，在这里分析的情况下，模板参数将实例化为 <code>PhaseCompressibleTurbulenceModel&lt;phaseModel&gt;</code> ，所以， <code>RASModel</code> 类也将继承自 <code>PhaseCompressibleTurbulenceModel&lt;phaseModel&gt;</code>。</p>
<p><code>PhaseCompressibleTurbulenceModel</code> 类定义如下：<br><figure class="highlight nimrod"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">template</span>&lt;class <span class="type">TransportModel</span>&gt;</span><br><span class="line">class <span class="type">PhaseCompressibleTurbulenceModel</span></span><br><span class="line">:</span><br><span class="line">    public <span class="type">TurbulenceModel</span></span><br><span class="line">    &lt;</span><br><span class="line">        volScalarField,</span><br><span class="line">        volScalarField,</span><br><span class="line">        compressibleTurbulenceModel,</span><br><span class="line">        <span class="type">TransportModel</span></span><br><span class="line">    &gt;</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">public:</span><br><span class="line"></span><br><span class="line">    typedef volScalarField alphaField;</span><br><span class="line">    typedef volScalarField rhoField;</span><br><span class="line">    typedef <span class="type">TransportModel</span> transportModel;</span><br><span class="line">    ......</span><br><span class="line">    ......</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">template</span>&lt;class <span class="type">TransportModel</span>&gt;</span><br><span class="line"><span class="type">Foam</span>::<span class="type">PhaseCompressibleTurbulenceModel</span>&lt;<span class="type">TransportModel</span>&gt;::</span><br><span class="line"><span class="type">PhaseCompressibleTurbulenceModel</span></span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> volScalarField&amp; alpha,</span><br><span class="line">    <span class="keyword">const</span> volScalarField&amp; rho,</span><br><span class="line">    <span class="keyword">const</span> volVectorField&amp; U,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; phi,</span><br><span class="line">    <span class="keyword">const</span> transportModel&amp; transport,</span><br><span class="line">    <span class="keyword">const</span> word&amp; propertiesName</span><br><span class="line">)</span><br><span class="line">:</span><br><span class="line">    <span class="type">TurbulenceModel</span></span><br><span class="line">    &lt;</span><br><span class="line">        volScalarField,</span><br><span class="line">        volScalarField,</span><br><span class="line">        compressibleTurbulenceModel,</span><br><span class="line">        transportModel</span><br><span class="line">    &gt;</span><br><span class="line">    (</span><br><span class="line">        alpha,</span><br><span class="line">        rho,</span><br><span class="line">        U,</span><br><span class="line">        alphaRhoPhi,</span><br><span class="line">        phi,</span><br><span class="line">        transport,</span><br><span class="line">        propertiesName</span><br><span class="line">    )</span><br><span class="line">&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<p>可见， <code>PhaseCompressibleTurbulenceModel</code> 类继承自 <code>TurbulenceModel</code> 类，并且要注意给 <code>TurbulenceModel</code> 的模板代入的实例化参数。</p>
<p>继续深入，来看 <code>TurbulenceModel</code> 的定义，<br><figure class="highlight monkey"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line">template</span><br><span class="line">&lt;</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Alpha</span>,</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Rho</span>,</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">BasicTurbulenceModel</span>,</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">TransportModel</span></span></span><br><span class="line">&gt;</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">TurbulenceModel</span></span></span><br><span class="line">:</span><br><span class="line">    <span class="keyword">public</span> BasicTurbulenceModel</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line"></span><br><span class="line">    typedef Alpha alphaField;</span><br><span class="line">    typedef Rho rhoField;</span><br><span class="line">    typedef TransportModel transportModel;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">protected:</span><br><span class="line"></span><br><span class="line">    // Protected data</span><br><span class="line"></span><br><span class="line">        <span class="keyword">const</span> alphaField&amp; alpha_;</span><br><span class="line">        <span class="keyword">const</span> transportModel&amp; transport_;</span><br><span class="line">        ......</span><br><span class="line">        ......</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">template</span><br><span class="line">&lt;</span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Alpha</span>,</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">Rho</span>,</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">BasicTurbulenceModel</span>,</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">TransportModel</span></span></span><br><span class="line">&gt;</span><br><span class="line">Foam::TurbulenceModel&lt;Alpha, Rho, BasicTurbulenceModel, TransportModel&gt;::</span><br><span class="line">TurbulenceModel</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> alphaField&amp; alpha,</span><br><span class="line">    <span class="keyword">const</span> rhoField&amp; rho,</span><br><span class="line">    <span class="keyword">const</span> volVectorField&amp; U,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; phi,</span><br><span class="line">    <span class="keyword">const</span> transportModel&amp; transport,</span><br><span class="line">    <span class="keyword">const</span> word&amp; propertiesName</span><br><span class="line">)</span><br><span class="line">:</span><br><span class="line">    BasicTurbulenceModel</span><br><span class="line">    (</span><br><span class="line">        rho,</span><br><span class="line">        U,</span><br><span class="line">        alphaRhoPhi,</span><br><span class="line">        phi,</span><br><span class="line">        propertiesName</span><br><span class="line">    ),</span><br><span class="line">    alpha_(alpha),</span><br><span class="line">    transport_(transport)</span><br><span class="line">&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<p> <code>TurbulenceModel</code> 继承自模板的第三个参数对应的类，从 <code>PhaseCompressibleTurbulenceModel</code> 的定义可知，这里是 <code>compressibleTurbulenceModel</code> 。此外，还要注意这个类有一个数据成员是 <code>alpha_</code>，在派生类的某些地方会调用这个数据成员。</p>
<p>接着再看， <code>compressibleTurbulenceModel</code>，<br><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> compressibleTurbulenceModel</span><br><span class="line">:</span><br><span class="line">    <span class="keyword">public</span> turbulenceModel</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line"><span class="keyword">protected</span>:</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Protected data</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">const</span> volScalarField&amp; rho_;</span><br><span class="line">    ......</span><br><span class="line">    ......</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">Foam::compressibleTurbulenceModel::compressibleTurbulenceModel</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> volScalarField&amp; rho,</span><br><span class="line">    <span class="keyword">const</span> volVectorField&amp; U,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; phi,</span><br><span class="line">    <span class="keyword">const</span> word&amp; propertiesName</span><br><span class="line">)</span><br><span class="line">:</span><br><span class="line">    turbulenceModel</span><br><span class="line">    (</span><br><span class="line">        U,</span><br><span class="line">        alphaRhoPhi,</span><br><span class="line">        phi,</span><br><span class="line">        propertiesName</span><br><span class="line">    ),</span><br><span class="line">    rho_(rho)</span><br><span class="line">&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<p>这个类继承自 <code>turbulenceModel</code> ，并且有一个数据成员 <code>rho_</code> 。</p>
<p>最底层的是 <code>turbulenceModel</code> 类了，其定义如下：<br><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> turbulenceModel</span><br><span class="line">:</span><br><span class="line">    public IOdictionary</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">protected:</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Protected data</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">const</span> Time&amp; runTime_;</span><br><span class="line">        <span class="keyword">const</span> fvMesh&amp; mesh_;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">const</span> volVectorField&amp; U_;</span><br><span class="line">        <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi_;</span><br><span class="line">        <span class="keyword">const</span> surfaceScalarField&amp; phi_;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//- Near wall distance boundary field</span></span><br><span class="line">        nearWallDist y_;</span><br><span class="line">        ......</span><br><span class="line">        ......</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">Foam::turbulenceModel::turbulenceModel</span><br><span class="line">(</span><br><span class="line">    <span class="keyword">const</span> volVectorField&amp; <span class="keyword">U</span>,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; alphaRhoPhi,</span><br><span class="line">    <span class="keyword">const</span> surfaceScalarField&amp; phi,</span><br><span class="line">    <span class="keyword">const</span> word&amp; propertiesName</span><br><span class="line">)</span><br><span class="line">:</span><br><span class="line">    IOdictionary</span><br><span class="line">    (</span><br><span class="line">        IOobject</span><br><span class="line">        (</span><br><span class="line">            IOobject::groupName(propertiesName, <span class="keyword">U</span>.<span class="literal">group</span>()),</span><br><span class="line">            <span class="keyword">U</span>.time().constant(),</span><br><span class="line">            <span class="keyword">U</span>.<span class="keyword">db</span>(),</span><br><span class="line">            IOobject::MUST_READ_IF_MODIFIED,</span><br><span class="line">            IOobject::NO_WRITE</span><br><span class="line">        )</span><br><span class="line">    ),</span><br><span class="line"></span><br><span class="line">    runTime_(<span class="keyword">U</span>.time()),</span><br><span class="line">    mesh_(<span class="keyword">U</span>.mesh()),</span><br><span class="line">    U_(<span class="keyword">U</span>),</span><br><span class="line">    alphaRhoPhi_(alphaRhoPhi),</span><br><span class="line">    phi_(phi),</span><br><span class="line">    y_(mesh_)</span><br><span class="line">&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<p>这个类里定义了数据成员 <code>U_</code>，在 <code>kineticTheoryModel</code> 类中用到了。 </p>
<p>总结一下，湍流模型的继承派生关系如下图（看大图请右键点击图片，选“在新标签页中打开”）：</p>
<p><img src="/image/TFM/turbulenceModel.png" alt=""></p>
<p>像上面这种“类继承其模板参数所代表的类”的用法，在 OpenFOAM 中使用很普遍，最近在看的 thermodynamics 相关的代码里也大量使用了这种模式。不知道这是不是一种 C++ 的 design pattern？这方面我的理解还很浅显。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://xiaopingqiu.github.io/2015/09/19/TFM-TurbulenceModel/" data-id="cj2lay35j004nkkmb7pok8ev1" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Code-Explained/">Code Explained</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2015/10/06/blockMesh-multi-sectional-grading/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          blockMesh 的新功能：multi/sectional grading in a block
        
      </div>
    </a>
  
  
    <a href="/2015/09/19/kineticTheoryModelSubModels/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">OpenFOAM-2.3.x 中的 twoPhaseEulerFoam 解析之 kineticTheoryModel 的子模型</div>
    </a>
  
</nav>

  
</article>


<section id="comments">
  <!-- 多说评论框 start -->
  <div class="ds-thread" data-thread-key="post-TFM-TurbulenceModel" data-title="OpenFOAM-2.3.x 中的 twoPhaseEulerFoam 解析之 TurbulenceModel" data-url="http://xiaopingqiu.github.io/2015/09/19/TFM-TurbulenceModel/"></div>
  <!-- 多说评论框 end -->
  <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
  <script type="text/javascript">
  var duoshuoQuery = {short_name:"xiaopingqiu"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
  <!-- 多说公共JS代码 end -->
</section>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/C/">C++</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/DEM/">DEM</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/OpenFOAM/">OpenFOAM</a><span class="category-list-count">44</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Paraview/">Paraview</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/swak4Foam/">swak4Foam</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/test/">test</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/vim/">vim</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Boundary-conditions/">Boundary conditions</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/">C++</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CentOS/">CentOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Code-Explained/">Code Explained</a><span class="tag-list-count">29</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LES/">LES</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LIGGGHTS/">LIGGGHTS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ODE/">ODE</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a><span class="tag-list-count">20</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Postprocessing/">Postprocessing</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Preprocessing/">Preprocessing</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RTS/">RTS</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TIL/">TIL</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Windows/">Windows</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fvOptions/">fvOptions</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovyBC/">groovyBC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/paraview/">paraview</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/thermophysicalModels/">thermophysicalModels</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/turbulence-model/">turbulence model</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wall-functions/">wall functions</a><span class="tag-list-count">4</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Boundary-conditions/" style="font-size: 15.56px;">Boundary conditions</a><a href="/tags/C/" style="font-size: 11.11px;">C++</a><a href="/tags/CentOS/" style="font-size: 10px;">CentOS</a><a href="/tags/Code-Explained/" style="font-size: 20px;">Code Explained</a><a href="/tags/LES/" style="font-size: 10px;">LES</a><a href="/tags/LIGGGHTS/" style="font-size: 10px;">LIGGGHTS</a><a href="/tags/ODE/" style="font-size: 10px;">ODE</a><a href="/tags/OpenFOAM/" style="font-size: 18.89px;">OpenFOAM</a><a href="/tags/Postprocessing/" style="font-size: 17.78px;">Postprocessing</a><a href="/tags/Preprocessing/" style="font-size: 11.11px;">Preprocessing</a><a href="/tags/RTS/" style="font-size: 12.22px;">RTS</a><a href="/tags/TIL/" style="font-size: 10px;">TIL</a><a href="/tags/Windows/" style="font-size: 10px;">Windows</a><a href="/tags/fvOptions/" style="font-size: 11.11px;">fvOptions</a><a href="/tags/groovyBC/" style="font-size: 10px;">groovyBC</a><a href="/tags/paraview/" style="font-size: 10px;">paraview</a><a href="/tags/test/" style="font-size: 11.11px;">test</a><a href="/tags/thermophysicalModels/" style="font-size: 14.44px;">thermophysicalModels</a><a href="/tags/turbulence-model/" style="font-size: 16.67px;">turbulence model</a><a href="/tags/vim/" style="font-size: 10px;">vim</a><a href="/tags/wall-functions/" style="font-size: 13.33px;">wall functions</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/">五月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">四月 2016</a><span class="archive-list-count">12</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">三月 2016</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">十一月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">十月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">九月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">八月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">六月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">五月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">四月 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/05/12/duoshuoAnnouncement/">多说评论系统将停止提供服务</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewScritps/">Paraview 脚本一例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCamera/">Paraview 中有关 Camera 的操作两例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCustomFilter/">Paraview 中创建 Custom Filter</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewStreamLineOnSlice/">在 Paraview 中画截面上的流线</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Giskard Q.<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

<script src="//dn-lbstatics.qbox.me/lbservice/busuanzi/2.0/busuanzi.mini.js"/></script>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/atom.xml" class="mobile-nav-link">Rss</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-62501686-1', 'auto');
  ga('send', 'pageview');

</script>

  </div>
<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</body>
</html>